package com.qidian.mes.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @Author 陆雯城
 * @Description
 * @Time 2024-04-15 2:00
 */
public class SubjectEnableStatusConverter implements Converter<Integer> {

    @Override
    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        // 是否启用 - 1是, 2否, 99删除
        return new WriteCellData<>(value == 1 ? "是": value == 2 ? "否" : "删除");
    }

    @Override
    public Integer convertToJavaData(ReadConverterContext<?> context) throws Exception {
        String enableStatus = context.getReadCellData().getStringValue();
        // 是否启用 - 1是, 2否, 99删除
        return enableStatus.equals("是") ? 1 : enableStatus.equals("否") ? 2 : 99;
    }
}